/**
 * Created by zhangsong on 2019-01-18.
 */
const result = require('../model/result');
const Sequelize = require('sequelize');

const Op = Sequelize.Op;

function create({
  point,
  date,
  level,
}) {
  return result.create({
    point,
    date,
    level,
  });
}

function createByMulti(obj) {
  return result.bulkCreate(obj);
}

function findByPage({ point = 0, limit = 100, date }) {
  return result.findAll({
    attributes: ['date', 'point', 'level'],
    where: {
      point: {
        [Op.gt]: point,
      },
      date,
    },
    order: [
      ['point', 'ASC'],
    ],
    limit,
  });
}

module.exports = {
  create,
  createByMulti,
  findByPage,
};


